package datamining.algorithms.gspan;

public class AttackGraphEdge {
	public enum Type {
        // 枚举列表必须写在最前面，否则编译出错
        none,	
        src, 
        dst, 
        src_dst, 
        edge_start,
        edge_mid, 
        edge_end;
    }
	
	public AttackGraphNode nodeA;
	public AttackGraphNode nodeB;
	public String label;
	public String insertString;
	public String stringA;
	public String stringB;
	public String stringA2B;
	public Type type = Type.none;

	/**
	 * nodeA、nodeB都已存在
	 * @param nodeA
	 * @param nodeB
	 * @param label
	 * @param type
	 */
	public AttackGraphEdge(AttackGraphNode nodeA, AttackGraphNode nodeB, String label, Type type){	//nodeA已存在，nodeB已存在
		this.nodeA = nodeA;
		this.nodeB = nodeB;
		this.label = label;
		this.type = type;
		changeNodeDegree();
	}
	
	/**
	 * nodeA不存在，nodeB已存在
	 * @param nodeLabelA
	 * @param idA
	 * @param nodeB
	 * @param label
	 * @param type
	 */
	public AttackGraphEdge(String nodeLabelA, int idA, AttackGraphNode nodeB, String label, Type type){
		this.nodeA = new AttackGraphNode(nodeLabelA, idA);
		this.nodeB = nodeB;
		this.label = label;
		this.type = type;
		changeNodeDegree();
	}
	
	/**
	 * nodeA已存在，nodeB不存在
	 * @param nodeA
	 * @param nodeLabelB
	 * @param idB
	 * @param label
	 * @param type
	 */
	public AttackGraphEdge(AttackGraphNode nodeA, String nodeLabelB, int idB, String label, Type type){
		this.nodeA = nodeA;
		this.nodeB = new AttackGraphNode(nodeLabelB, idB);
		this.label = label;
		this.type = type;
		changeNodeDegree();
	}
	
	/**
	 * nodeA、nodeB都不存在
	 * @param nodeLabelA
	 * @param idA
	 * @param nodeLabelB
	 * @param idB
	 * @param edgeLabel
	 * @param type
	 */
	public AttackGraphEdge(String nodeLabelA, int idA, String nodeLabelB, int idB, String edgeLabel, Type type){
		this.nodeA = new AttackGraphNode(nodeLabelA, idA);
		this.nodeB = new AttackGraphNode(nodeLabelB, idB);
		this.label = edgeLabel;
		this.type = type;
		changeNodeDegree();
	}
	
	public void setType(Type type){
		this.type = type;
	}
	
	public void changeNodeDegree(){
		this.nodeA.addOutDegree();
		this.nodeB.addInDegree();
	}
	
	
	public String toString(){
		stringA = "node" + nodeA.id + " [label=\"" + nodeA.label + "\"];\n";
		stringB = "node" + nodeB.id + " [label=\"" + nodeB.label + "\"];\n";
		stringA2B = "node" + nodeA.id + " -> " + "node" + nodeB.id + " [label=\"" + label + "\"];\n";
		
		switch(type){
		case edge_start:	//源目地址相同: A->B, A->B, 但事件类型不同，已有事件的类型
			stringB = "node" + nodeB.id + " [label=\"\"];\n";
			//stringA = "";
			break;
		case edge_mid:	//源目地址相同: A->B, A->B, 但事件类型不同，新事件的类型
			stringA = "";
			stringB = "node" + nodeB.id + " [label=\"\"];\n";
			break;
		case edge_end:	//源目地址相同: A->B, A->B, 但事件类型不同，新事件的类型
			stringA = "";
			break;
		case src:	//新加入边的源地址已存在，但目标地址是新的
			stringA = "";
			break;
		case dst:	//新加入边的目标地址已存在，但源地址是新的
			stringB = "";
			break;
		case src_dst:	//新加入边的源目地址都已存在
			stringA = "";
			stringB = "";
			break;
		case none:

			
			break;
		default:	////全新的事件或新事件目标与已有事件源一致
		
			break;
		}
		
		insertString = stringA + stringB + stringA2B;
		
		return insertString;
	}
	
}
